package com.fyp.ptma.dao.service;

import java.util.List;

import javax.persistence.PersistenceException;

import org.hibernate.HibernateException;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fyp.ptma.dao.repository.irepository.IApplicationDao;
import com.fyp.ptma.dao.service.iservice.IApplicationService;
import com.fyp.ptma.model.Application;
import com.fyp.ptma.model.ApplicationVersion;
import com.fyp.ptma.model.ApplicationVersionPk;
import com.fyp.ptma.model.Downloader;

/**
 * 
 * @author YahyaArshad
 * 
 */

@Service
public class ApplicationService implements IApplicationService {

	@Autowired
	private IApplicationDao applicationDao;

	@Transactional
	public Long save(Object objToSave) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub
		return applicationDao.save(objToSave);
	}

	@Transactional
	public Long update(Object objToUpdate) throws PersistenceException {
		// TODO Auto-generated method stub
		return applicationDao.update(objToUpdate);
	}

	@Transactional
	public boolean delete(Object objToDelete) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub
		return applicationDao.delete(objToDelete);
	}

	@Transactional
	public List<ApplicationVersion> getAllApplicationVersions(
			Application application) throws HibernateException {
		// TODO Auto-generated method stub
		return applicationDao.getAllApplicationVersions(application);
	}

	@Transactional
	public Application getApplicationByUserAndNameSpace(String user,
			String nameSpace) throws HibernateException {
		return applicationDao.getApplicationByUserAndNameSpace(user, nameSpace);
	}

	@Transactional
	public boolean deleteApplicationVersion(ApplicationVersion appVersion)
			throws HibernateException {
		// TODO Auto-generated method stub
		return applicationDao.deleteApplicationVersion(appVersion);
	}

	@Transactional
	public Long save(Application objToSave) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub
		return applicationDao.save(objToSave);
	}

	@Transactional
	public Long save(ApplicationVersion objToSave) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub
		return applicationDao.save(objToSave);
	}

	@Transactional
	public void saveOrUpdate(Object objToSave) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub

	}

	@Transactional
	public ApplicationVersion getApplicationVersionByPk(
			ApplicationVersionPk versionPk, String devEmail)
			throws HibernateException {
		return applicationDao.getApplicationVersionByPk(versionPk, devEmail);
	}

	@Transactional
	public List<Downloader> getAllDevicesFor(Application application)
			throws HibernateException {
		return applicationDao.getAllDevicesFor(application);
	}

}
